/*======================================================================*
    Copyright (c) 2015-2023 DTS, Inc. and its affiliates.

    Redistribution and use in source and binary forms, with or without modification,
    are permitted provided that the following conditions are met:

    1. Redistributions of source code must retain the above copyright notice, this
    list of conditions and the following disclaimer.

    2. Redistributions in binary form must reproduce the above copyright notice,
    this list of conditions and the following disclaimer in the documentation
    and/or other materials provided with the distribution.

    3. Neither the name of the copyright holder nor the names of its contributors
    may be used to endorse or promote products derived from this software without
    specific prior written permission.

    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
    ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
    WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
    DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
    ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
    (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
    LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
    ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
    (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
    SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *======================================================================*/

#ifndef __MDATOIABCONVCONSTANTS_H__
#define	__MDATOIABCONVCONSTANTS_H__

/*
 * This header file was originally generated using scripts : iabcore/tests/scripts/mda_to_iab_tables_generate/generate.m.
 * 
 * The following supplementary information on the related coordinate systems is added here for convenience and
 * developers can find full detail in the original documents:
 *
 * IAB coordinate system (extracted from SMPTE-2098-2 Section 11.1)
 *
 * "Axes and Origin"
 * The origin is taken to be the front left corner of the room. Position is then described using Cartesian (x,y,z) coordinates,
 * assigned as follows:
 *      x: lateral, or left/right position
 *          x=0 corresponds to left wall;
 *          x=1 corresponds to right wall.
 *      y: longitude, or front/back position
 *          y=0 corresponds to front wall;
 *          y=1 corresponds to back wall.
 *      z: elevation, or up/down position
 *          z=0 corresponds to a horizontal plane at of the height of the main screen Loudspeakers, the side and rear surround Loudspeakers;
 *          z=1 corresponds to the ceiling.
 *
 * Pro Tools (PT) coordinate system:
 *
 * X range [-100, 100]
 *      X : -100 = left, 100 = right
 * Y range [-100, 100]
 *      Y : 100 = Front (screen), -100 = back
 * Z range [0, 100]
 *      Z : 0 = bottom, 100 = top
 *
 * MDA coordinate system: See MDA Program Specification Section 5 and Recommended_Practices_for_MDA_Production_Internal document
 *
 * The listener is located at the origin O = (0,0,0), facing the front of the room;
 * The positive z-axis is perpendicular to the floor of the room, and directed to the ceiling;
 * The positive y-axis is directed towards the front of the room;
 * The positive x-axis is directed to the right of the listener;
 * Loudspeakers lie on the unit sphere S; and
 * The unit circle in the x-y plane is the locus of traditional horizontal two-dimensional loudspeaker configurations.
 * x, y, z are related to spherical coordinates by the following, theta = azimuth angle, phi = elevation angle :
 *  x = radius * sin(theta) * cos(phi)
 *  y = radius * cos(theta) * cos(phi)
 *  z = radius * sin(phi)
 *
 * For current MDA VBAP implemenation, radius = 1.
 * See Recommended_Practices_for_MDA_Production_Internal document (RP) for a description on Pyra-mesa and vertices, coordinates and angles.
 */

#include <stdint.h>

#include "coreutils/Matrix3.h"
#include "coreutils/Vector3.h"

using namespace CoreUtils;

namespace SMPTE
{
namespace ImmersiveAudioBitstream
{

    /* Number of pyra-mesa vertices */
    static const int32_t num_vertices = 29;
    
    /*
     * In const float vertices[29][6] array below:
     *
     * iab_x/y/z = Pro tools coordinates/100
     * mda_x/y/z is the x,y,x coordinates of the vertex in the MDA system, generated from
     * the corresponding pyra-mesa azimuth and elevation angles.
     *
     * Spherical azimuth/elevation angles (in degrees) are added as inline comments for supplementary information.
     * These are taken from Recommended_Practices_for_MDA_Production_Internal document
     */

    /*
     * Coordinates of pyra-mesa vertices 
     * (iab_x, iab_y, iab_z, mda_x, mda_y, mda_z) */

    const float vertices[29][6] = {
        
        /*
         * ========================================
         *
         * Vertices on right half of pyra-mesa
         *
         * ========================================
         */
         
      /* Vertex 1 at [100, -100, 100]. Pyra-mesa spherical : 155.2/36 */
              {1.00000000000f, -1.00000000000f, 1.00000000000f, 0.339275571900f, -0.734553160300f, 0.587642528200f},
      /* Vertex 2 at [100, -100, 50]. Pyra-mesa spherical : 150/21 */
              {1.00000000000f, -1.00000000000f, 0.500000000000f, 0.466821527100f, -0.808558603000f, 0.358204756300f},
      /* Vertex 3 at [100, -75, 50]. Pyra-mesa spherical : 135/22.2. This is the (RP) Rsh speaker array back end point */
              {1.00000000000f, -0.750000000000f, 0.500000000000f, 0.654653670700f, -0.654653670700f, 0.377964473000f},
      /* Vertex 4 at [100, -100, 0]. Pyra-mesa spherical : 150/0. This is the (RP) Rrs speaker position */
              {1.00000000000f, -1.00000000000f, 0.00000000000f, 0.500000000000f, -0.866025403800f, 0.00000000000f},
      /* Vertex 5 at [100, -75, 0]. Pyra-mesa spherical : 135/0. This is the (RP) Rss speaker array back end point */
              {1.00000000000f, -0.750000000000f, 0.00000000000f, 0.707106781200f, -0.707106781200f, 0.00000000000f},
      /* Vertex 6 at [100, 0, 100]. Pyra-mesa spherical : 90/60. This is the (RP) Rts speaker position */
              {1.00000000000f, 0.00000000000f, 1.00000000000f, 0.500000000000f, 0.00000000000f, 0.866025403800f},
      /* Vertex 7 at [100, 0, 50]. Pyra-mesa spherical : 90/30. This is the (RP) Rsh speaker position */
              {1.00000000000f, 0.00000000000f, 0.500000000000f, 0.866025403800f, 0.00000000000f, 0.500000000000f},
      /* Vertex 8 at [100, 0, 0]. Pyra-mesa spherical : 90/0. This is the (RP) Rss speaker position */
              {1.00000000000f, 0.00000000000f, 0.00000000000f, 1.00000000000f, 0.00000000000f, 0.00000000000f},
      /* Vertex 9 at [100, 100, 100]. Pyra-mesa spherical : 24.8/36 */
              {1.00000000000f, 1.00000000000f, 1.00000000000f, 0.339275571900f, 0.734553160300f, 0.587642528200f},
      /* Vertex 10 at [100, 75, 50]. Pyra-mesa spherical : 45/22.2. This is the (RP) Rsh speaker array front end point */
              {1.00000000000f, 0.750000000000f, 0.500000000000f, 0.654653670700f, 0.654653670700f, 0.377964473000f},
      /* Vertex 11 at [100, 75, 0]. Pyra-mesa spherical : 45/0. This is the (RP) Rss speaker array front end point */
              {1.00000000000f, 0.750000000000f, 0.00000000000f, 0.707106781200f, 0.707106781200f, 0.00000000000f},
      /* Vertex 12 at [100, 100, 50]. Pyra-mesa spherical : 30/21. This is the (RP) Rh speaker position */
              {1.00000000000f, 1.00000000000f, 0.500000000000f, 0.466821527100f, 0.808558603000f, 0.358204756300f},
      /* Vertex 13 at [100, 100, 0]. Pyra-mesa spherical : 30/0. This is the (RP) R speaker position */
              {1.00000000000f, 1.00000000000f, 0.00000000000f, 0.500000000000f, 0.866025403800f, 0.00000000000f},
        
        /*
         * ========================================
         *
         * Vertices at center of pyra-mesa
         *
         * ========================================
         */

      /* Vertex 14 at [0, 100, 100]. Pyra-mesa spherical : 0/38.7. This is the (RP) Tsc speaker position */
              {0.00000000000f, 1.00000000000f, 1.00000000000f, 0.00000000000f, 0.780868809400f, 0.624695047600f},
      /* Vertex 15 at [0, 100, 50] */
              {0.00000000000f, 1.00000000000f, 0.500000000000f, 0.00000000000f, 0.914295456400f, 0.405047921000f},
      /* Vertex 16 at [0, 100, 0] */
              {0.00000000000f, 1.00000000000f, 0.00000000000f, 0.00000000000f, 1.00000000000f, 0.00000000000f},

        /*
         * ========================================
         *
         * Vertices on left half of pyra-mesa
         *
         * ========================================
         */
        
      /* Vertex 17 at [-100, -100, 100]. Pyra-mesa spherical : -155.2/36 */
              {-1.00000000000f, -1.00000000000f, 1.00000000000f, -0.339275571900f, -0.734553160300f, 0.587642528200f},
      /* Vertex 18 at [-100, -100, 50]. Pyra-mesa spherical : -150/21 */
              {-1.00000000000f, -1.00000000000f, 0.500000000000f, -0.466821527100f, -0.808558603000f, 0.358204756300f},
      /* Vertex 19 at [-100, -75, 50]. Pyra-mesa spherical : -135/22.2. This is the (RP) Lsh speaker array back end point */
              {-1.00000000000f, -0.750000000000f, 0.500000000000f, -0.654653670700f, -0.654653670700f, 0.377964473000f},
      /* Vertex 20 at [-100, -100, 0]. Pyra-mesa spherical : -150/0. This is the (RP) Lrs speaker position */
              {-1.00000000000f, -1.00000000000f, 0.00000000000f, -0.500000000000f, -0.866025403800f, 0.00000000000f},
      /* Vertex 21 at [-100, -75, 0]. Pyra-mesa spherical : -135/0. This is the (RP) Lss speaker array back end point */
              {-1.00000000000f, -0.750000000000f, 0.00000000000f, -0.707106781200f, -0.707106781200f, 0.00000000000f},
      /* Vertex 22 at [-100, 0, 100]. Pyra-mesa spherical : -90/60. This is the (RP) Lts speaker position */
              {-1.00000000000f, 0.00000000000f, 1.00000000000f, -0.500000000000f, 0.00000000000f, 0.866025403800f},
      /* Vertex 23 at [-100, 0, 50]. Pyra-mesa spherical : -90/30. This is the (RP) Lsh speaker position */
              {-1.00000000000f, 0.00000000000f, 0.500000000000f, -0.866025403800f, 0.00000000000f, 0.500000000000f},
      /* Vertex 24 at [-100, 0, 0]. Pyra-mesa spherical : -90/0. This is the (RP) Lss speaker position */
              {-1.00000000000f, 0.00000000000f, 0.00000000000f, -1.00000000000f, 0.00000000000f, 0.00000000000f},
      /* Vertex 25 at [-100, 100, 100]. Pyra-mesa spherical : -24.8/36 */
              {-1.00000000000f, 1.00000000000f, 1.00000000000f, -0.339275571900f, 0.734553160300f, 0.587642528200f},
      /* Vertex 26 at [-100, 75, 50]. Pyra-mesa spherical : -45/22.2. This is the (RP) Lsh speaker array front end point*/
              {-1.00000000000f, 0.750000000000f, 0.500000000000f, -0.654653670700f, 0.654653670700f, 0.377964473000f},
      /* Vertex 27 at [-100, 75, 0]. Pyra-mesa spherical : -45/0. This is the (RP) Lss speaker array front end point */
              {-1.00000000000f, 0.750000000000f, 0.00000000000f, -0.707106781200f, 0.707106781200f, 0.00000000000f},
      /* Vertex 28 at [-100, 100, 50]. Pyra-mesa spherical : -30/21. This is the (RP) Lh speaker position */
              {-1.00000000000f, 1.00000000000f, 0.500000000000f, -0.466821527100f, 0.808558603000f, 0.358204756300f},
      /* Vertex 29 at [-100, 100, 0]. Pyra-mesa spherical : -30/0. This is the (RP) L speaker position */
              {-1.00000000000f, 1.00000000000f, 0.00000000000f, -0.500000000000f, 0.866025403800f, 0.00000000000f},
    };

    /* Number of pyra-mesa patches */
    static const int32_t num_patches = 51;

    /*
     * A (triangular) patch is made up of 3 of the vertices. The patches form a convex hull of the vertices of the pyra-mesa.
     * Some of the patches in the pyra-mesa are "quads", i.e. enclosed by 4 vertices and these are divided into two patches.
     *
     * Note that each vertex has 3 points and each point has x,y,z coordinate, so [3][3].
     * The inverse matrix is the inverse of the patch matrix.
     */

    /* Inverse of the pyra-mesa patch basis matrix in the MDA coordinate system */
    static float mda_inv_basis_table[num_patches][3][3] = {
      {
      /* Patch 1 with vertices 1, 2, 3*/
        {-1.09909068247f, -1.65493920761f, 3.27723797183f},
        {0.897403784218f, -3.96422776217f, 2.36173681565f},
        {3.45802985337f, -3.99980510589f, 1.06005679421f}
      },
      {
      /* Patch 2 with vertices 1, 2, 17*/
        {1.47372826520f, -0.00000000000f, -1.47372826520f},
        {2.75150204651f, -2.77159821013f, -1.06204014786f},
        {4.29023496914f, -3.46449776290f, -0.476692774152f}
      },
      {
      /* Patch 3 with vertices 1, 2, 18*/
        {0.00000000000f, 1.07107314246f, -1.07107314246f},
        {1.68946189865f, -1.99973089548f, -0.771867314656f},
        {3.81354219499f, -3.11804798674f, -0.346449776161f}
      },
      {
      /* Patch 4 with vertices 1, 3, 6*/
        {-2.04205778593f, 2.29128784776f, 0.385640646010f},
        {-1.36137185731f, 1.95124805202e-10f, 0.923760430657f},
        {1.17898261239f, -1.32287565567f, 0.932050807578f}
      },
      {
      /* Patch 5 with vertices 1, 6, 17*/
        {1.47372826520f, 0.00000000000f, -1.47372826520f},
        {-1.36137185701f, 0.923760430624f, -1.25501831150e-10f},
        {-0.850857410609f, 1.15470053836f, 0.850857410609f}
      },
      {
      /* Patch 6 with vertices 1, 6, 22*/
        {0.00000000000f, 1.00000000000f, -1.00000000000f},
        {-1.36137185713f, 0.923760430709f, -8.51594350593e-11f},
        {0.00000000000f, 0.577350269179f, 0.577350269179f}
      },
      {
      /* Patch 7 with vertices 1, 17, 18*/
        {1.47372826520f, -1.47372826520f, 0.00000000000f},
        {-1.06204014786f, 2.75150204651f, -2.77159821013f},
        {-0.476692774152f, 4.29023496914f, -3.46449776290f}
      },
      {
      /* Patch 8 with vertices 1, 17, 22*/
        {1.47372826520f, -1.47372826520f, 0.00000000000f},
        {-1.25502053194e-10f, -1.36137185701f, 0.923760430624f},
        {0.850857410609f, -0.850857410609f, 1.15470053836f}
      },
      {
      /* Patch 9 with vertices 2, 3, 5*/
        {-2.92622624386f, 2.77324519483f, 0.778539072024f},
        {-2.92622624386f, 2.77324519483f, -0.635674490323f},
        {0.00000000000f, 2.64575131113f, -2.44948974277f}
      },
      {
      /* Patch 10 with vertices 2, 4, 5*/
        {-0.00000000000f, -2.73205080745f, 3.34606521481f},
        {0.00000000000f, -2.73205080745f, 1.93185165246f},
        {2.79169939096f, -2.60645074564f, -1.00421649383e-10f}
      },
      {
      /* Patch 11 with vertices 2, 4, 18*/
        {1.07107314246f, -0.00000000000f, -1.07107314246f},
        {0.618384367111f, -1.15470053836f, -0.618384367111f},
        {2.79169939092f, -2.60645074572f, 3.21448999560e-11f}
      },
      {
      /* Patch 12 with vertices 2, 4, 20*/
        {0.00000000000f, 1.00000000000f, -1.00000000000f},
        {0.00000000000f, -0.577350269179f, -0.577350269179f},
        {2.79169939096f, -2.60645074575f, 3.00118625719e-11f}
      },
      {
      /* Patch 13 with vertices 2, 17, 18*/
        {1.07107314246f, -2.22044604925e-16f, -1.07107314246f},
        {-0.771867314656f, 1.68946189865f, -1.99973089548f},
        {-0.346449776161f, 3.81354219499f, -3.11804798674f}
      },
      {
      /* Patch 14 with vertices 2, 18, 20*/
        {1.07107314246f, -1.07107314246f, 0.00000000000f},
        {-0.618384367111f, 0.618384367111f, -1.15470053836f},
        {3.21454182760e-11f, 2.79169939092f, -2.60645074572f}
      },
      {
      /* Patch 15 with vertices 3, 5, 8*/
        {0.00000000000f, 0.00000000000f, 1.00000000000f},
        {-2.22044604925e-16f, -1.41421356235f, 1.00000000000f},
        {2.64575131113f, -2.44948974277f, 0.00000000000f}
      },
      {
      /* Patch 16 with vertices 3, 6, 7*/
        {0.00000000000f, -0.999999999946f, 1.73205080751f},
        {-1.52752523167f, 5.74118530463e-12f, 1.15470053836f},
        {0.00000000000f, 1.73205080751f, -0.999999999946f}
      },
      {
      /* Patch 17 with vertices 3, 7, 8*/
        {0.00000000000f, 0.00000000000f, 1.00000000000f},
        {-1.52752523167f, 1.15470053837f, -5.74118530494e-12f},
        {0.00000000000f, 2.00000000000f, -1.73205080760f}
      },
      {
      /* Patch 18 with vertices 4, 18, 20*/
        {1.00000000000f, 0.00000000000f, -1.00000000000f},
        {-0.577350269179f, 0.00000000000f, -0.577350269179f},
        {3.00118625722e-11f, 2.79169939096f, -2.60645074575f}
      },
      {
      /* Patch 19 with vertices 6, 7, 10*/
        {-0.999999999946f, 1.73205080751f, 0.00000000000f},
        {-5.74102409003e-12f, -1.15470053836f, 1.52752523167f},
        {1.73205080751f, -0.999999999946f, 0.00000000000f}
      },
      {
      /* Patch 20 with vertices 6, 9, 10*/
        {0.385640646010f, -2.04205778593f, 2.29128784776f},
        {-0.923760430657f, 1.36137185731f, -1.95124940574e-10f},
        {0.932050807578f, 1.17898261239f, -1.32287565567f}
      },
      {
      /* Patch 21 with vertices 6, 9, 14*/
        {3.92262256287e-10f, 2.94745652982f, -2.77263412594f},
        {-0.923760430624f, 1.36137185688f, 2.36116151702e-10f},
        {1.15470053813f, -1.70171482088f, 1.60078105895f}
      },
      {
      /* Patch 22 with vertices 6, 14, 22*/
        {1.00000000000f, 0.00000000000f, -1.00000000000f},
        {-0.461880215403f, 1.28062484756f, -0.461880215403f},
        {0.577350269179f, 0.00000000000f, 0.577350269179f}
      },
      {
      /* Patch 23 with vertices 6, 17, 22*/
        {1.00000000000f, -0.00000000000f, -1.00000000000f},
        {-8.51595460816e-11f, -1.36137185713f, 0.923760430709f},
        {0.577350269179f, 0.00000000000f, 0.577350269179f}
      },
      {
      /* Patch 24 with vertices 7, 8, 10*/
        {0.00000000000f, 1.00000000000f, 0.00000000000f},
        {-1.15470053837f, 5.74109752808e-12f, 1.52752523167f},
        {2.00000000000f, -1.73205080760f, 0.00000000000f}
      },
      {
      /* Patch 25 with vertices 8, 10, 11*/
        {1.00000000000f, 0.00000000000f, 0.00000000000f},
        {-1.00000000000f, 2.22044604925e-16f, 1.41421356235f},
        {0.00000000000f, 2.64575131113f, -2.44948974277f}
      },
      {
      /* Patch 26 with vertices 9, 10, 12*/
        {-1.09909068247f, 3.27723797183f, -1.65493920761f},
        {-0.897403784218f, -2.36173681565f, 3.96422776217f},
        {3.45802985337f, 1.06005679421f, -3.99980510589f}
      },
      {
      /* Patch 27 with vertices 9, 12, 15*/
        {5.23154452166e-11f, 2.14214628489f, -1.89441038501f},
        {-1.68946189869f, 1.22786358085f, 1.36520411050f},
        {3.81354219501f, -2.77159821059f, -0.612766792316f}
      },
      {
      /* Patch 28 with vertices 9, 14, 15*/
        {2.94745653039f, -2.77263412526f, -1.04081186586e-09f},
        {-2.22044604925e-16f, -1.58925489330f, 2.45106716946f},
        {6.80307801522e-16f, 3.58734967562f, -3.06383396143f}
      },
      {
      /* Patch 29 with vertices 10, 11, 12*/
        {2.77324519483f, 0.778539072024f, -2.92622624386f},
        {-2.77324519483f, 0.635674490323f, 2.92622624386f},
        {2.64575131113f, -2.44948974277f, 0.00000000000f}
      },
      {
      /* Patch 30 with vertices 11, 12, 13*/
        {3.34606521481f, 0.00000000000f, -2.73205080745f},
        {-1.93185165246f, -0.00000000000f, 2.73205080745f},
        {-1.00422337113e-10f, 2.79169939096f, -2.60645074564f}
      },
      {
      /* Patch 31 with vertices 12, 13, 16*/
        {0.00000000000f, 2.00000000000f, -1.73205080760f},
        {0.00000000000f, 0.00000000000f, 1.00000000000f},
        {2.79169939096f, -2.60645074578f, 5.19820708052e-11f}
      },
      {
      /* Patch 32 with vertices 12, 15, 16*/
        {2.14214628492f, -1.89441038496f, -3.09655314139e-11f},
        {0.00000000000f, -2.22044604925e-16f, 1.00000000000f},
        {5.01210752792e-16f, 2.46884368035f, -2.25725255951f}
      },
      {
      /* Patch 33 with vertices 14, 15, 25*/
        {2.77263412526f, 1.04081153293e-09f, -2.94745653039f},
        {-1.58925489330f, 2.45106716946f, 0.00000000000f},
        {3.58734967562f, -3.06383396143f, 0.00000000000f}
      },
      {
      /* Patch 34 with vertices 14, 22, 25*/
        {2.77263412594f, -3.92261999930e-10f, -2.94745652982f},
        {2.36116015628e-10f, -0.923760430624f, 1.36137185688f},
        {1.60078105895f, 1.15470053813f, -1.70171482088f}
      },
      {
      /* Patch 35 with vertices 15, 16, 28*/
        {1.89441038496f, 3.09653543794e-11f, -2.14214628492f},
        {0.00000000000f, 1.00000000000f, 0.00000000000f},
        {2.46884368035f, -2.25725255951f, 0.00000000000f}
      },
      {
      /* Patch 36 with vertices 15, 25, 28*/
        {1.89441038501f, -5.23150411880e-11f, -2.14214628489f},
        {1.36520411050f, -1.68946189869f, 1.22786358085f},
        {-0.612766792316f, 3.81354219501f, -2.77159821059f}
      },
      {
      /* Patch 37 with vertices 16, 28, 29*/
        {1.73205080760f, -4.44089209850e-16f, -2.00000000000f},
        {1.00000000000f, 0.00000000000f, 0.00000000000f},
        {5.19825959023e-11f, 2.79169939096f, -2.60645074578f}
      },
      {
      /* Patch 38 with vertices 17, 18, 19*/
        {1.09909068247f, 1.65493920761f, -3.27723797183f},
        {0.897403784218f, -3.96422776217f, 2.36173681565f},
        {3.45802985337f, -3.99980510589f, 1.06005679421f}
      },
      {
      /* Patch 39 with vertices 17, 19, 22*/
        {2.04205778593f, -2.29128784776f, -0.385640646010f},
        {-1.36137185731f, 1.95124805202e-10f, 0.923760430657f},
        {1.17898261239f, -1.32287565567f, 0.932050807578f}
      },
      {
      /* Patch 40 with vertices 18, 19, 21*/
        {2.92622624386f, -2.77324519483f, -0.778539072024f},
        {-2.92622624386f, 2.77324519483f, -0.635674490323f},
        {0.00000000000f, 2.64575131113f, -2.44948974277f}
      },
      {
      /* Patch 41 with vertices 18, 20, 21*/
        {0.00000000000f, 2.73205080745f, -3.34606521481f},
        {0.00000000000f, -2.73205080745f, 1.93185165246f},
        {2.79169939096f, -2.60645074564f, -1.00421649383e-10f}
      },
      {
      /* Patch 42 with vertices 19, 21, 24*/
        {0.00000000000f, 0.00000000000f, -1.00000000000f},
        {-2.22044604925e-16f, -1.41421356235f, 1.00000000000f},
        {2.64575131113f, -2.44948974277f, 0.00000000000f}
      },
      {
      /* Patch 43 with vertices 19, 22, 23*/
        {0.00000000000f, 0.999999999946f, -1.73205080751f},
        {-1.52752523167f, 5.74118530463e-12f, 1.15470053836f},
        {0.00000000000f, 1.73205080751f, -0.999999999946f}
      },
      {
      /* Patch 44 with vertices 19, 23, 24*/
        {0.00000000000f, 0.00000000000f, -1.00000000000f},
        {-1.52752523167f, 1.15470053837f, -5.74118530494e-12f},
        {0.00000000000f, 2.00000000000f, -1.73205080760f}
      },
      {
      /* Patch 45 with vertices 22, 23, 26*/
        {0.999999999946f, -1.73205080751f, 0.00000000000f},
        {-5.74102409003e-12f, -1.15470053836f, 1.52752523167f},
        {1.73205080751f, -0.999999999946f, 0.00000000000f}
      },
      {
      /* Patch 46 with vertices 22, 25, 26*/
        {-0.385640646010f, 2.04205778593f, -2.29128784776f},
        {-0.923760430657f, 1.36137185731f, -1.95124940574e-10f},
        {0.932050807578f, 1.17898261239f, -1.32287565567f}
      },
      {
      /* Patch 47 with vertices 23, 24, 26*/
        {0.00000000000f, -1.00000000000f, 0.00000000000f},
        {-1.15470053837f, 5.74109752808e-12f, 1.52752523167f},
        {2.00000000000f, -1.73205080760f, 0.00000000000f}
      },
      {
      /* Patch 48 with vertices 24, 26, 27*/
        {-1.00000000000f, 0.00000000000f, 0.00000000000f},
        {-1.00000000000f, 2.22044604925e-16f, 1.41421356235f},
        {0.00000000000f, 2.64575131113f, -2.44948974277f}
      },
      {
      /* Patch 49 with vertices 25, 26, 28*/
        {1.09909068247f, -3.27723797183f, 1.65493920761f},
        {-0.897403784218f, -2.36173681565f, 3.96422776217f},
        {3.45802985337f, 1.06005679421f, -3.99980510589f}
      },
      {
      /* Patch 50 with vertices 26, 27, 28*/
        {-2.77324519483f, -0.778539072024f, 2.92622624386f},
        {-2.77324519483f, 0.635674490323f, 2.92622624386f},
        {2.64575131113f, -2.44948974277f, 0.00000000000f}
      },
      {
      /* Patch 51 with vertices 27, 28, 29*/
        {-3.34606521481f, 0.00000000000f, 2.73205080745f},
        {-1.93185165246f, -0.00000000000f, 2.73205080745f},
        {-1.00422337113e-10f, 2.79169939096f, -2.60645074564f}
      }
    };

    /* Pyra-mesa patch basis matrix in the IAB coordinate system */
    static float iab_basis_table[num_patches][3][3] = {
      {
      /* Patch 1 with vertices 1, 2, 3*/
        {1.00000000000f, -1.00000000000f, 1.00000000000f},
        {1.00000000000f, -1.00000000000f, 0.500000000000f},
        {1.00000000000f, -0.750000000000f, 0.500000000000f}
      },
      {
      /* Patch 2 with vertices 1, 2, 17*/
        {1.00000000000f, -1.00000000000f, 1.00000000000f},
        {1.00000000000f, -1.00000000000f, 0.500000000000f},
        {-1.00000000000f, -1.00000000000f, 1.00000000000f}
      },
      {
      /* Patch 3 with vertices 1, 2, 18*/
        {1.00000000000f, -1.00000000000f, 1.00000000000f},
        {1.00000000000f, -1.00000000000f, 0.500000000000f},
        {-1.00000000000f, -1.00000000000f, 0.500000000000f}
      },
      {
      /* Patch 4 with vertices 1, 3, 6*/
        {1.00000000000f, -1.00000000000f, 1.00000000000f},
        {1.00000000000f, -0.750000000000f, 0.500000000000f},
        {1.00000000000f, 0.00000000000f, 1.00000000000f}
      },
      {
      /* Patch 5 with vertices 1, 6, 17*/
        {1.00000000000f, -1.00000000000f, 1.00000000000f},
        {1.00000000000f, 0.00000000000f, 1.00000000000f},
        {-1.00000000000f, -1.00000000000f, 1.00000000000f}
      },
      {
      /* Patch 6 with vertices 1, 6, 22*/
        {1.00000000000f, -1.00000000000f, 1.00000000000f},
        {1.00000000000f, 0.00000000000f, 1.00000000000f},
        {-1.00000000000f, 0.00000000000f, 1.00000000000f}
      },
      {
      /* Patch 7 with vertices 1, 17, 18*/
        {1.00000000000f, -1.00000000000f, 1.00000000000f},
        {-1.00000000000f, -1.00000000000f, 1.00000000000f},
        {-1.00000000000f, -1.00000000000f, 0.500000000000f}
      },
      {
      /* Patch 8 with vertices 1, 17, 22*/
        {1.00000000000f, -1.00000000000f, 1.00000000000f},
        {-1.00000000000f, -1.00000000000f, 1.00000000000f},
        {-1.00000000000f, 0.00000000000f, 1.00000000000f}
      },
      {
      /* Patch 9 with vertices 2, 3, 5*/
        {1.00000000000f, -1.00000000000f, 0.500000000000f},
        {1.00000000000f, -0.750000000000f, 0.500000000000f},
        {1.00000000000f, -0.750000000000f, 0.00000000000f}
      },
      {
      /* Patch 10 with vertices 2, 4, 5*/
        {1.00000000000f, -1.00000000000f, 0.500000000000f},
        {1.00000000000f, -1.00000000000f, 0.00000000000f},
        {1.00000000000f, -0.750000000000f, 0.00000000000f}
      },
      {
      /* Patch 11 with vertices 2, 4, 18*/
        {1.00000000000f, -1.00000000000f, 0.500000000000f},
        {1.00000000000f, -1.00000000000f, 0.00000000000f},
        {-1.00000000000f, -1.00000000000f, 0.500000000000f}
      },
      {
      /* Patch 12 with vertices 2, 4, 20*/
        {1.00000000000f, -1.00000000000f, 0.500000000000f},
        {1.00000000000f, -1.00000000000f, 0.00000000000f},
        {-1.00000000000f, -1.00000000000f, 0.00000000000f}
      },
      {
      /* Patch 13 with vertices 2, 17, 18*/
        {1.00000000000f, -1.00000000000f, 0.500000000000f},
        {-1.00000000000f, -1.00000000000f, 1.00000000000f},
        {-1.00000000000f, -1.00000000000f, 0.500000000000f}
      },
      {
      /* Patch 14 with vertices 2, 18, 20*/
        {1.00000000000f, -1.00000000000f, 0.500000000000f},
        {-1.00000000000f, -1.00000000000f, 0.500000000000f},
        {-1.00000000000f, -1.00000000000f, 0.00000000000f}
      },
      {
      /* Patch 15 with vertices 3, 5, 8*/
        {1.00000000000f, -0.750000000000f, 0.500000000000f},
        {1.00000000000f, -0.750000000000f, 0.00000000000f},
        {1.00000000000f, 0.00000000000f, 0.00000000000f}
      },
      {
      /* Patch 16 with vertices 3, 6, 7*/
        {1.00000000000f, -0.750000000000f, 0.500000000000f},
        {1.00000000000f, 0.00000000000f, 1.00000000000f},
        {1.00000000000f, 0.00000000000f, 0.500000000000f}
      },
      {
      /* Patch 17 with vertices 3, 7, 8*/
        {1.00000000000f, -0.750000000000f, 0.500000000000f},
        {1.00000000000f, 0.00000000000f, 0.500000000000f},
        {1.00000000000f, 0.00000000000f, 0.00000000000f}
      },
      {
      /* Patch 18 with vertices 4, 18, 20*/
        {1.00000000000f, -1.00000000000f, 0.00000000000f},
        {-1.00000000000f, -1.00000000000f, 0.500000000000f},
        {-1.00000000000f, -1.00000000000f, 0.00000000000f}
      },
      {
      /* Patch 19 with vertices 6, 7, 10*/
        {1.00000000000f, 0.00000000000f, 1.00000000000f},
        {1.00000000000f, 0.00000000000f, 0.500000000000f},
        {1.00000000000f, 0.750000000000f, 0.500000000000f}
      },
      {
      /* Patch 20 with vertices 6, 9, 10*/
        {1.00000000000f, 0.00000000000f, 1.00000000000f},
        {1.00000000000f, 1.00000000000f, 1.00000000000f},
        {1.00000000000f, 0.750000000000f, 0.500000000000f}
      },
      {
      /* Patch 21 with vertices 6, 9, 14*/
        {1.00000000000f, 0.00000000000f, 1.00000000000f},
        {1.00000000000f, 1.00000000000f, 1.00000000000f},
        {0.00000000000f, 1.00000000000f, 1.00000000000f}
      },
      {
      /* Patch 22 with vertices 6, 14, 22*/
        {1.00000000000f, 0.00000000000f, 1.00000000000f},
        {0.00000000000f, 1.00000000000f, 1.00000000000f},
        {-1.00000000000f, 0.00000000000f, 1.00000000000f}
      },
      {
      /* Patch 23 with vertices 6, 17, 22*/
        {1.00000000000f, 0.00000000000f, 1.00000000000f},
        {-1.00000000000f, -1.00000000000f, 1.00000000000f},
        {-1.00000000000f, 0.00000000000f, 1.00000000000f}
      },
      {
      /* Patch 24 with vertices 7, 8, 10*/
        {1.00000000000f, 0.00000000000f, 0.500000000000f},
        {1.00000000000f, 0.00000000000f, 0.00000000000f},
        {1.00000000000f, 0.750000000000f, 0.500000000000f}
      },
      {
      /* Patch 25 with vertices 8, 10, 11*/
        {1.00000000000f, 0.00000000000f, 0.00000000000f},
        {1.00000000000f, 0.750000000000f, 0.500000000000f},
        {1.00000000000f, 0.750000000000f, 0.00000000000f}
      },
      {
      /* Patch 26 with vertices 9, 10, 12*/
        {1.00000000000f, 1.00000000000f, 1.00000000000f},
        {1.00000000000f, 0.750000000000f, 0.500000000000f},
        {1.00000000000f, 1.00000000000f, 0.500000000000f}
      },
      {
      /* Patch 27 with vertices 9, 12, 15*/
        {1.00000000000f, 1.00000000000f, 1.00000000000f},
        {1.00000000000f, 1.00000000000f, 0.500000000000f},
        {0.00000000000f, 1.00000000000f, 0.500000000000f}
      },
      {
      /* Patch 28 with vertices 9, 14, 15*/
        {1.00000000000f, 1.00000000000f, 1.00000000000f},
        {0.00000000000f, 1.00000000000f, 1.00000000000f},
        {0.00000000000f, 1.00000000000f, 0.500000000000f}
      },
      {
      /* Patch 29 with vertices 10, 11, 12*/
        {1.00000000000f, 0.750000000000f, 0.500000000000f},
        {1.00000000000f, 0.750000000000f, 0.00000000000f},
        {1.00000000000f, 1.00000000000f, 0.500000000000f}
      },
      {
      /* Patch 30 with vertices 11, 12, 13*/
        {1.00000000000f, 0.750000000000f, 0.00000000000f},
        {1.00000000000f, 1.00000000000f, 0.500000000000f},
        {1.00000000000f, 1.00000000000f, 0.00000000000f}
      },
      {
      /* Patch 31 with vertices 12, 13, 16*/
        {1.00000000000f, 1.00000000000f, 0.500000000000f},
        {1.00000000000f, 1.00000000000f, 0.00000000000f},
        {0.00000000000f, 1.00000000000f, 0.00000000000f}
      },
      {
      /* Patch 32 with vertices 12, 15, 16*/
        {1.00000000000f, 1.00000000000f, 0.500000000000f},
        {0.00000000000f, 1.00000000000f, 0.500000000000f},
        {0.00000000000f, 1.00000000000f, 0.00000000000f}
      },
      {
      /* Patch 33 with vertices 14, 15, 25*/
        {0.00000000000f, 1.00000000000f, 1.00000000000f},
        {0.00000000000f, 1.00000000000f, 0.500000000000f},
        {-1.00000000000f, 1.00000000000f, 1.00000000000f}
      },
      {
      /* Patch 34 with vertices 14, 22, 25*/
        {0.00000000000f, 1.00000000000f, 1.00000000000f},
        {-1.00000000000f, 0.00000000000f, 1.00000000000f},
        {-1.00000000000f, 1.00000000000f, 1.00000000000f}
      },
      {
      /* Patch 35 with vertices 15, 16, 28*/
        {0.00000000000f, 1.00000000000f, 0.500000000000f},
        {0.00000000000f, 1.00000000000f, 0.00000000000f},
        {-1.00000000000f, 1.00000000000f, 0.500000000000f}
      },
      {
      /* Patch 36 with vertices 15, 25, 28*/
        {0.00000000000f, 1.00000000000f, 0.500000000000f},
        {-1.00000000000f, 1.00000000000f, 1.00000000000f},
        {-1.00000000000f, 1.00000000000f, 0.500000000000f}
      },
      {
      /* Patch 37 with vertices 16, 28, 29*/
        {0.00000000000f, 1.00000000000f, 0.00000000000f},
        {-1.00000000000f, 1.00000000000f, 0.500000000000f},
        {-1.00000000000f, 1.00000000000f, 0.00000000000f}
      },
      {
      /* Patch 38 with vertices 17, 18, 19*/
        {-1.00000000000f, -1.00000000000f, 1.00000000000f},
        {-1.00000000000f, -1.00000000000f, 0.500000000000f},
        {-1.00000000000f, -0.750000000000f, 0.500000000000f}
      },
      {
      /* Patch 39 with vertices 17, 19, 22*/
        {-1.00000000000f, -1.00000000000f, 1.00000000000f},
        {-1.00000000000f, -0.750000000000f, 0.500000000000f},
        {-1.00000000000f, 0.00000000000f, 1.00000000000f}
      },
      {
      /* Patch 40 with vertices 18, 19, 21*/
        {-1.00000000000f, -1.00000000000f, 0.500000000000f},
        {-1.00000000000f, -0.750000000000f, 0.500000000000f},
        {-1.00000000000f, -0.750000000000f, 0.00000000000f}
      },
      {
      /* Patch 41 with vertices 18, 20, 21*/
        {-1.00000000000f, -1.00000000000f, 0.500000000000f},
        {-1.00000000000f, -1.00000000000f, 0.00000000000f},
        {-1.00000000000f, -0.750000000000f, 0.00000000000f}
      },
      {
      /* Patch 42 with vertices 19, 21, 24*/
        {-1.00000000000f, -0.750000000000f, 0.500000000000f},
        {-1.00000000000f, -0.750000000000f, 0.00000000000f},
        {-1.00000000000f, 0.00000000000f, 0.00000000000f}
      },
      {
      /* Patch 43 with vertices 19, 22, 23*/
        {-1.00000000000f, -0.750000000000f, 0.500000000000f},
        {-1.00000000000f, 0.00000000000f, 1.00000000000f},
        {-1.00000000000f, 0.00000000000f, 0.500000000000f}
      },
      {
      /* Patch 44 with vertices 19, 23, 24*/
        {-1.00000000000f, -0.750000000000f, 0.500000000000f},
        {-1.00000000000f, 0.00000000000f, 0.500000000000f},
        {-1.00000000000f, 0.00000000000f, 0.00000000000f}
      },
      {
      /* Patch 45 with vertices 22, 23, 26*/
        {-1.00000000000f, 0.00000000000f, 1.00000000000f},
        {-1.00000000000f, 0.00000000000f, 0.500000000000f},
        {-1.00000000000f, 0.750000000000f, 0.500000000000f}
      },
      {
      /* Patch 46 with vertices 22, 25, 26*/
        {-1.00000000000f, 0.00000000000f, 1.00000000000f},
        {-1.00000000000f, 1.00000000000f, 1.00000000000f},
        {-1.00000000000f, 0.750000000000f, 0.500000000000f}
      },
      {
      /* Patch 47 with vertices 23, 24, 26*/
        {-1.00000000000f, 0.00000000000f, 0.500000000000f},
        {-1.00000000000f, 0.00000000000f, 0.00000000000f},
        {-1.00000000000f, 0.750000000000f, 0.500000000000f}
      },
      {
      /* Patch 48 with vertices 24, 26, 27*/
        {-1.00000000000f, 0.00000000000f, 0.00000000000f},
        {-1.00000000000f, 0.750000000000f, 0.500000000000f},
        {-1.00000000000f, 0.750000000000f, 0.00000000000f}
      },
      {
      /* Patch 49 with vertices 25, 26, 28*/
        {-1.00000000000f, 1.00000000000f, 1.00000000000f},
        {-1.00000000000f, 0.750000000000f, 0.500000000000f},
        {-1.00000000000f, 1.00000000000f, 0.500000000000f}
      },
      {
      /* Patch 50 with vertices 26, 27, 28*/
        {-1.00000000000f, 0.750000000000f, 0.500000000000f},
        {-1.00000000000f, 0.750000000000f, 0.00000000000f},
        {-1.00000000000f, 1.00000000000f, 0.500000000000f}
      },
      {
      /* Patch 51 with vertices 27, 28, 29*/
        {-1.00000000000f, 0.750000000000f, 0.00000000000f},
        {-1.00000000000f, 1.00000000000f, 0.500000000000f},
        {-1.00000000000f, 1.00000000000f, 0.00000000000f}
      }
    };

    /* Normal vectors of pyra-mesa patches in the IAB coordinate system */
    const Vector3 iabPatchNormalVector[51] = {

      /* Patch 1 with vertices 1, 2, 3*/
      Vector3(0.125000000000f, 0.00000000000f, 0.00000000000f),

      /* Patch 2 with vertices 1, 2, 17*/
      Vector3(0.00000000000f, 1.00000000000f, 0.00000000000f),

      /* Patch 3 with vertices 1, 2, 18*/
      Vector3(0.00000000000f, 1.00000000000f, 0.00000000000f),

      /* Patch 4 with vertices 1, 3, 6*/
      Vector3(0.500000000000f, -0.00000000000f, 0.00000000000f),

      /* Patch 5 with vertices 1, 6, 17*/
      Vector3(0.00000000000f, -0.00000000000f, 2.00000000000f),

      /* Patch 6 with vertices 1, 6, 22*/
      Vector3(0.00000000000f, -0.00000000000f, 2.00000000000f),

      /* Patch 7 with vertices 1, 17, 18*/
      Vector3(-0.00000000000f, -1.00000000000f, 0.00000000000f),

      /* Patch 8 with vertices 1, 17, 22*/
      Vector3(0.00000000000f, 0.00000000000f, -2.00000000000f),

      /* Patch 9 with vertices 2, 3, 5*/
      Vector3(-0.125000000000f, 0.00000000000f, 0.00000000000f),

      /* Patch 10 with vertices 2, 4, 5*/
      Vector3(0.125000000000f, 0.00000000000f, 0.00000000000f),

      /* Patch 11 with vertices 2, 4, 18*/
      Vector3(0.00000000000f, 1.00000000000f, 0.00000000000f),

      /* Patch 12 with vertices 2, 4, 20*/
      Vector3(0.00000000000f, 1.00000000000f, 0.00000000000f),

      /* Patch 13 with vertices 2, 17, 18*/
      Vector3(0.00000000000f, -1.00000000000f, 0.00000000000f),

      /* Patch 14 with vertices 2, 18, 20*/
      Vector3(-0.00000000000f, -1.00000000000f, 0.00000000000f),

      /* Patch 15 with vertices 3, 5, 8*/
      Vector3(0.375000000000f, 0.00000000000f, 0.00000000000f),

      /* Patch 16 with vertices 3, 6, 7*/
      Vector3(-0.375000000000f, 0.00000000000f, 0.00000000000f),

      /* Patch 17 with vertices 3, 7, 8*/
      Vector3(-0.375000000000f, 0.00000000000f, 0.00000000000f),

      /* Patch 18 with vertices 4, 18, 20*/
      Vector3(0.00000000000f, -1.00000000000f, 0.00000000000f),

      /* Patch 19 with vertices 6, 7, 10*/
      Vector3(0.375000000000f, 0.00000000000f, 0.00000000000f),

      /* Patch 20 with vertices 6, 9, 10*/
      Vector3(-0.500000000000f, 0.00000000000f, 0.00000000000f),

      /* Patch 21 with vertices 6, 9, 14*/
      Vector3(0.00000000000f, -0.00000000000f, 1.00000000000f),

      /* Patch 22 with vertices 6, 14, 22*/
      Vector3(0.00000000000f, 0.00000000000f, 2.00000000000f),

      /* Patch 23 with vertices 6, 17, 22*/
      Vector3(-0.00000000000f, 0.00000000000f, -2.00000000000f),

      /* Patch 24 with vertices 7, 8, 10*/
      Vector3(0.375000000000f, -0.00000000000f, 0.00000000000f),

      /* Patch 25 with vertices 8, 10, 11*/
      Vector3(-0.375000000000f, 0.00000000000f, 0.00000000000f),

      /* Patch 26 with vertices 9, 10, 12*/
      Vector3(0.125000000000f, 0.00000000000f, 0.00000000000f),

      /* Patch 27 with vertices 9, 12, 15*/
      Vector3(0.00000000000f, 0.500000000000f, 0.00000000000f),

      /* Patch 28 with vertices 9, 14, 15*/
      Vector3(-0.00000000000f, -0.500000000000f, 0.00000000000f),

      /* Patch 29 with vertices 10, 11, 12*/
      Vector3(0.125000000000f, -0.00000000000f, 0.00000000000f),

      /* Patch 30 with vertices 11, 12, 13*/
      Vector3(-0.125000000000f, 0.00000000000f, 0.00000000000f),

      /* Patch 31 with vertices 12, 13, 16*/
      Vector3(0.00000000000f, 0.500000000000f, 0.00000000000f),

      /* Patch 32 with vertices 12, 15, 16*/
      Vector3(-0.00000000000f, -0.500000000000f, 0.00000000000f),

      /* Patch 33 with vertices 14, 15, 25*/
      Vector3(0.00000000000f, 0.500000000000f, 0.00000000000f),

      /* Patch 34 with vertices 14, 22, 25*/
      Vector3(-0.00000000000f, 0.00000000000f, -1.00000000000f),

      /* Patch 35 with vertices 15, 16, 28*/
      Vector3(0.00000000000f, 0.500000000000f, 0.00000000000f),

      /* Patch 36 with vertices 15, 25, 28*/
      Vector3(0.00000000000f, -0.500000000000f, 0.00000000000f),

      /* Patch 37 with vertices 16, 28, 29*/
      Vector3(0.00000000000f, -0.500000000000f, 0.00000000000f),

      /* Patch 38 with vertices 17, 18, 19*/
      Vector3(0.125000000000f, 0.00000000000f, 0.00000000000f),

      /* Patch 39 with vertices 17, 19, 22*/
      Vector3(0.500000000000f, -0.00000000000f, 0.00000000000f),

      /* Patch 40 with vertices 18, 19, 21*/
      Vector3(-0.125000000000f, 0.00000000000f, 0.00000000000f),

      /* Patch 41 with vertices 18, 20, 21*/
      Vector3(0.125000000000f, 0.00000000000f, 0.00000000000f),

      /* Patch 42 with vertices 19, 21, 24*/
      Vector3(0.375000000000f, 0.00000000000f, 0.00000000000f),

      /* Patch 43 with vertices 19, 22, 23*/
      Vector3(-0.375000000000f, 0.00000000000f, 0.00000000000f),

      /* Patch 44 with vertices 19, 23, 24*/
      Vector3(-0.375000000000f, 0.00000000000f, 0.00000000000f),

      /* Patch 45 with vertices 22, 23, 26*/
      Vector3(0.375000000000f, 0.00000000000f, 0.00000000000f),

      /* Patch 46 with vertices 22, 25, 26*/
      Vector3(-0.500000000000f, 0.00000000000f, 0.00000000000f),

      /* Patch 47 with vertices 23, 24, 26*/
      Vector3(0.375000000000f, -0.00000000000f, 0.00000000000f),

      /* Patch 48 with vertices 24, 26, 27*/
      Vector3(-0.375000000000f, 0.00000000000f, 0.00000000000f),

      /* Patch 49 with vertices 25, 26, 28*/
      Vector3(0.125000000000f, 0.00000000000f, 0.00000000000f),

      /* Patch 50 with vertices 26, 27, 28*/
      Vector3(0.125000000000f, -0.00000000000f, 0.00000000000f),

      /* Patch 51 with vertices 27, 28, 29*/
      Vector3(-0.125000000000f, 0.00000000000f, 0.00000000000f)
    };

    /* Projection of a pyra-mesa patch basis onto its normal vector in the IAB coordinate system */
    const float iabBasisNormalProjection[51] = {

      /* Patch 1 with vertices 1, 2, 3*/
     0.125000000000f,

      /* Patch 2 with vertices 1, 2, 17*/
     -1.00000000000f,

      /* Patch 3 with vertices 1, 2, 18*/
     -1.00000000000f,

      /* Patch 4 with vertices 1, 3, 6*/
     0.500000000000f,

      /* Patch 5 with vertices 1, 6, 17*/
     2.00000000000f,

      /* Patch 6 with vertices 1, 6, 22*/
     2.00000000000f,

      /* Patch 7 with vertices 1, 17, 18*/
     1.00000000000f,

      /* Patch 8 with vertices 1, 17, 22*/
     -2.00000000000f,

      /* Patch 9 with vertices 2, 3, 5*/
     -0.125000000000f,

      /* Patch 10 with vertices 2, 4, 5*/
     0.125000000000f,

      /* Patch 11 with vertices 2, 4, 18*/
     -1.00000000000f,

      /* Patch 12 with vertices 2, 4, 20*/
     -1.00000000000f,

      /* Patch 13 with vertices 2, 17, 18*/
     1.00000000000f,

      /* Patch 14 with vertices 2, 18, 20*/
     1.00000000000f,

      /* Patch 15 with vertices 3, 5, 8*/
     0.375000000000f,

      /* Patch 16 with vertices 3, 6, 7*/
     -0.375000000000f,

      /* Patch 17 with vertices 3, 7, 8*/
     -0.375000000000f,

      /* Patch 18 with vertices 4, 18, 20*/
     1.00000000000f,

      /* Patch 19 with vertices 6, 7, 10*/
     0.375000000000f,

      /* Patch 20 with vertices 6, 9, 10*/
     -0.500000000000f,

      /* Patch 21 with vertices 6, 9, 14*/
     1.00000000000f,

      /* Patch 22 with vertices 6, 14, 22*/
     2.00000000000f,

      /* Patch 23 with vertices 6, 17, 22*/
     -2.00000000000f,

      /* Patch 24 with vertices 7, 8, 10*/
     0.375000000000f,

      /* Patch 25 with vertices 8, 10, 11*/
     -0.375000000000f,

      /* Patch 26 with vertices 9, 10, 12*/
     0.125000000000f,

      /* Patch 27 with vertices 9, 12, 15*/
     0.500000000000f,

      /* Patch 28 with vertices 9, 14, 15*/
     -0.500000000000f,

      /* Patch 29 with vertices 10, 11, 12*/
     0.125000000000f,

      /* Patch 30 with vertices 11, 12, 13*/
     -0.125000000000f,

      /* Patch 31 with vertices 12, 13, 16*/
     0.500000000000f,

      /* Patch 32 with vertices 12, 15, 16*/
     -0.500000000000f,

      /* Patch 33 with vertices 14, 15, 25*/
     0.500000000000f,

      /* Patch 34 with vertices 14, 22, 25*/
     -1.00000000000f,

      /* Patch 35 with vertices 15, 16, 28*/
     0.500000000000f,

      /* Patch 36 with vertices 15, 25, 28*/
     -0.500000000000f,

      /* Patch 37 with vertices 16, 28, 29*/
     -0.500000000000f,

      /* Patch 38 with vertices 17, 18, 19*/
     -0.125000000000f,

      /* Patch 39 with vertices 17, 19, 22*/
     -0.500000000000f,

      /* Patch 40 with vertices 18, 19, 21*/
     0.125000000000f,

      /* Patch 41 with vertices 18, 20, 21*/
     -0.125000000000f,

      /* Patch 42 with vertices 19, 21, 24*/
     -0.375000000000f,

      /* Patch 43 with vertices 19, 22, 23*/
     0.375000000000f,

      /* Patch 44 with vertices 19, 23, 24*/
     0.375000000000f,

      /* Patch 45 with vertices 22, 23, 26*/
     -0.375000000000f,

      /* Patch 46 with vertices 22, 25, 26*/
     0.500000000000f,

      /* Patch 47 with vertices 23, 24, 26*/
     -0.375000000000f,

      /* Patch 48 with vertices 24, 26, 27*/
     0.375000000000f,

      /* Patch 49 with vertices 25, 26, 28*/
     -0.125000000000f,

      /* Patch 50 with vertices 26, 27, 28*/
     -0.125000000000f,

      /* Patch 51 with vertices 27, 28, 29*/
     0.125000000000f
    };

} // namespace ImmersiveAudioBitstream
} // namespace SMPTE

#endif // __MDATOIABCONVCONSTANTS_H__
